package com.imooc.scala

import org.apache.spark.sql.SparkSession

object DataFrameApp {

  def main(args: Array[String]): Unit = {
    val spark = SparkSession.builder().appName("DataFrameApp").master("local[*]").getOrCreate()
    val peopleDF = spark.read.format("json").load("people.json")
    peopleDF.printSchema()


    peopleDF.show()

    peopleDF.select("name").show()

    peopleDF.select(peopleDF.col("name"),(peopleDF.col("age")+10).as("age2")).show()

    peopleDF.filter(peopleDF.col("age")>19).show()
    peopleDF.where(peopleDF.col("age")>19).show()

    peopleDF.groupBy("age").count().show()
    spark.stop()
  }
}
